<template>
  <div class="main_box">
    <div class="main_content">
      <div class="info_card">
        <div class="head">
          <div class="left">
            <i></i>
            <span>我的任务</span>
          </div>
          <div class="right" @click="toHelpList"><i></i></div>
        </div>
        <div class="content">干事业就要有钉钉子精神，抓铁有痕、路石留印，稳扎授打向前走，过了一山再登一峰，跨过一沟再越一壑，不断通过化解难题开创工作新局面。</div>
      </div>
      <div class="nav_box">
        <div class="nav_item" @click="toOther">
          <div class="left">
            <i class="icon icon1"></i>
            <div>日常工作</div>
          </div>
          <div class="right">
            <i class="icon"></i>
          </div>
        </div>
        <div class="nav_item" @click="toIndex">
          <div class="left">
            <i class="icon icon2"></i>
            <div>人事贯通</div>
          </div>
          <div class="right">
            <i class="icon"></i>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "HomePage",
  data() {
    return {
      hasRole: false,
      userInfo: {}
    };
  },

  created() {
    // this.initRole();
    this.$nextTick(() => {
      this.ddInit();
    });
  },
  methods: {
    ddInit() {
      // 钉钉免登
      // eslint-disable-next-line
      dd.ready(() => {
        // eslint-disable-next-line
        dd.getAuthCode({ corpId: "196729" })
          .then(res => {
            if (res) {
              // 获取免登码 调用免登接口 获取用户信息 及 ticket
              if (res.code) {
                const params = {
                  code: res.code
                };
                this.$api.login(params).then(res => {
                  if (res.errno === 200) {
                    this.hasRole = true;
                    this.userInfo = res.data;
                    sessionStorage.setItem("employId", res.data.empId);
                    sessionStorage.setItem("areaId", res.data.areaId);
                  } else {
                    this.hasRole = false;
                    this.$dialog.alert({
                      message: "抱歉，您暂时没有权限"
                    });
                  }
                });
              }
            }
          })
          .catch(err => {
            console.log(err);
          });
      });
    },

    initRole() {
      const params = {
        _gp: "employee", //组织名
        _mt: "getEmployeeId", //方法明
        zid: this.$route.query.zid || "78829732" // 78301388 市管领导 78829732 区主管 65564850 区主值   10825433  白洪楞
      };
      this.$api.commonApi(params).then(res => {
        if (res.errno === 200) {
          this.hasRole = true;
          this.userInfo = res.data;
          sessionStorage.setItem("employId", res.data.empId);
          sessionStorage.setItem("areaId", res.data.areaId);
        } else {
          this.hasRole = false;
          this.$dialog.alert({
            message: "抱歉，您暂时没有权限"
          });
        }
      });
    },
    toIndex() {
      if (!this.hasRole) {
        this.$dialog.alert({
          message: "抱歉，您暂时没有权限"
        });
        return false;
      }
      this.$router.push({
        path: "/index",
        query: {
          ...this.userInfo
        }
      });
    },
    toHelpList() {
      if (!this.hasRole) {
        this.$dialog.alert({
          message: "抱歉，您暂时没有权限"
        });
        return false;
      }
      this.$router.push("/helpList");
    },
    toOther() {
      if (this.userInfo.areaId === "330304000000") {
        window.location.href =
          // "http://xcoa.ouhai.gov.cn/pages/sso-page/sso/index.html?DDfrom=zwdd";
          "https://mxcoa.ouhai.gov.cn:4300/#/";
      } else if (this.userInfo.areaId === "330382000000") {
        window.location.href = "https://yqoa-mobile.yueqing.gov.cn:10010/";
      } else {
        window.location.href = "https://em.wenzhou.gov.cn/spa/coms/static4mobile/index.html#/menu-preview?id=appDefaultPage&checkAccess=1";
      }
    }
  }
};
</script>

<style scoped>
.main_box {
  min-height: 100vh;
  background-color: #f4f5fa;
}
.main_content {
  padding: 10px 15px;
  box-sizing: border-box;
  text-align: left;
  background-color: #f4f5fa;
}
.info_card {
  width: 100%;
  padding: 15px;
  background: url("../assets/image/bg.png") no-repeat;
  background-size: cover;
  object-fit: fill;
  box-sizing: border-box;
  border-radius: 8px;
  color: #b5d0ff;
  font-size: 13px;
}
.info_card .head {
  font-size: 14px;
  color: #fff;
  margin-bottom: 15px;
  display: flex;
  justify-content: space-between;
  box-sizing: border-box;
}
.info_card .head .left i {
  display: inline-block;
  width: 15px;
  height: 12px;
  background: url("../assets/image/head_icon.png") no-repeat;
  background-size: 100% 100%;
  margin-right: 5px;
}
.info_card .head .right {
  position: relative;
  display: inline-block;
  width: 18px;
  height: 18px;
  background: url("../assets/image/notice.png") no-repeat;
  background-size: 100% 100%;
}
.info_card .head .right i {
  width: 5px;
  height: 5px;
  background-color: #f60e36;
  border-radius: 50%;
  position: absolute;
  right: -2px;
  top: -2px;
}
.nav_box {
  margin-top: 20px;
}
.nav_item {
  width: 100%;
  background-color: #fff;
  border-radius: 8px;
  margin-bottom: 20px;
  padding: 20px;
  box-sizing: border-box;
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  color: #333;
  cursor: pointer;
}
.nav_item * {
  cursor: pointer;
}
.nav_item .left {
  display: flex;
}
.nav_item .left .icon {
  display: inline-block;
  width: 32px;
  height: 32px;
  background: url("../assets/image/home_nav1.png") no-repeat;
  background-size: 100% 100%;
  margin-right: 20px;
}
.nav_item .left .icon.icon2 {
  background: url("../assets/image/home_nav2.png") no-repeat;
  background-size: 100% 100%;
}
.nav_item .left > div {
  height: 32px;
  line-height: 32px;
}
.nav_item .right .icon {
  display: inline-block;
  width: 32px;
  height: 32px;
  background: url("../assets/image/home_arrow.png") no-repeat;
  background-size: 100% 100%;
}
</style>
